package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.allen.library.SuperTextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.ui.park.ParkingSpaceBean;

import java.util.List;

/*
 * @Author:itchenqi175@163.com
 * @Time:2024/1/6  11:55
 * @Description:添加适配器逻辑
 */
public class ParkingSpaceAdapter extends BaseQuickAdapter<ParkingSpaceBean, BaseViewHolder> {

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param layoutResId The layout resource id of each item.
     * @param data        A new list is created out of this one to avoid mutable list
     */
    public ParkingSpaceAdapter(int layoutResId, @Nullable List<ParkingSpaceBean> data) {
        super(layoutResId, data);

        addChildClickViewIds(R.id.textviewspacein);

    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, ParkingSpaceBean parkingSpaceBean) {

        if (parkingSpaceBean != null) {

            SuperTextView superTextView = (SuperTextView) baseViewHolder.getView(R.id.textviewspacein);

            TextView textviewbottom = (TextView) baseViewHolder.getView(R.id.textviewparkingspacebottom);

            if (baseViewHolder.getAdapterPosition() == (this.getData().size() - 1)) {
                //如果是最后一段数据那么隐藏底部横线条
                textviewbottom.setVisibility(View.GONE);
            } else {
                textviewbottom.setVisibility(View.VISIBLE);
            }


            //做测试的内容
            String name = parkingSpaceBean.getParkSpaceStr();

            if (!TextUtils.isEmpty(name)) {
                superTextView.setLeftString(name);
            }

//            baseViewHolder.addOnClickListener(R.id.textviewspacein);


        }

    }
}
